function Base({
  page,
  scope,
  cmpt
}) {
  this.curPage = page;
  this.curScope = scope;
  this.curCmpt = cmpt;

  this._initMedFunc();
}

Base.prototype = {
  constructor: Base,

  _initMedFunc() {
    var _self = this;

    this.curPage['med_' + this.curScope] = function(evt) {
      var funcName = evt.target.dataset.medName;
      if (!funcName) {
        return;
      }
      var func = _self[funcName];

      if (!func) {
        return;
      }
      func.call(_self, evt);
    };
  },

  setData(data, isSimple) {
    var obj = this.getData(null, isSimple);

    Object.assign(obj, data);

    this.curPage.setData({
      [(isSimple ? '' : 'com.') + this.curScope]: obj
    });
  },

  getData(key, isSimple) {
    var data = this.curPage.data;

    if (!isSimple) {
      data = data['com'] || {};
    }
    data = data[this.curScope] || {};

    if (!key) {
      return data;
    } else {
      return data[key];
    }
  },
};

module.exports = Base;